import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import '../utils/adapt.dart';
import '../utils/request.dart';

class VideoList extends StatefulWidget {
  VideoList({Key? key}) : super(key: key);

  @override
  _VideoListState createState() => _VideoListState();
}

class _VideoListState extends State<VideoList> {
  var _list = [];
  void _getData() async {
    var res = await getHttp('/top/mv?limit=30');

    this.setState(() {
      _list = res['data'];
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _getData();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: Adapt.px(400),
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: _list.length,
        itemBuilder: (BuildContext context, int index) {
          return InkWell(
            onTap: () {
              var dataObj = _list[index];
              Navigator.pushNamed(context, "/videoplayer", arguments: {
                "vid": dataObj['id'],
                "cover": dataObj['cover'],
                "name": dataObj['name'],
                "desc": dataObj['desc'],
                "artistName": dataObj['artistName'],
              });
            },
            child: Container(
              height: Adapt.px(400),
              width: Adapt.px(300),
              margin: EdgeInsets.only(left: Adapt.px(20)),
              child: Column(
                children: [
                  Container(
                    width: Adapt.px(300),
                    height: Adapt.px(200),
                    child:
                        Image.network(_list[index]['cover'] + '?param=300y160'),
                  ),
                  Container(
                    padding: EdgeInsets.all(Adapt.px(10)),
                    width: Adapt.px(300),
                    height: Adapt.px(100),
                    child: Text(_list[index]['name'],
                        style: TextStyle(
                          fontSize: Adapt.px(30),
                          height: 1.5,
                        )),
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(horizontal: Adapt.px(10)),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          "区域",
                          style: TextStyle(fontSize: Adapt.px(26)),
                        ),
                        Text(
                          _list[index]['mv']['area'],
                          style: TextStyle(fontSize: Adapt.px(26)),
                        )
                      ],
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(horizontal: Adapt.px(10)),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Icon(
                          Icons.play_circle_fill,
                          size: Adapt.px(40),
                        ),
                        Text(
                          "${_list[index]['mv']['plays']}",
                          style: TextStyle(fontSize: Adapt.px(26)),
                        )
                      ],
                    ),
                  )
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}
